#A class representing the calculator's command history.
#It is actually just a fancy wrapper for an array.

#TODO MAKE THIS DEAL WITH VARIABLES AS WELL!

#Author: Sam Robertson
#Modified: 1/13/2012

class History
  def initialize
    @@myHistory = []
  end
  def print
    #TODO: We need to make this part more graceful, something besides the to_s command would be nice
    return @@myHistory.to_s
  end 
  def push(input)
    @@myHistory.push(input)
  end
  def length
    @@myHistory.length
  end
  def process(input)
    if(input == "!")
      input = self.print
      return input
    end
    if(input =~ /!([0-9]+)/)
      if (Integer($1) - 1 >= @@myHistory.length)
        input = "Bad history input, please use a between 1 and #{@@myHistory.length}."
        return input
      end
      input = @@myHistory[(Integer($1) - 1)]  
      return input
    end
  end
end
